package com.lagou.module4.work02;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class FileWriterTest {

    //编写程序，循环接收用户从键盘输入多个字符串，直到输入“end”时循环结束，并将所有已输入的字符串按字典顺序倒序录入到项目下abc.txt中
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        FileWriter fw = null;
        try {
            fw = new FileWriter("abc.txt");
            while(true){
                System.out.println("请输入一个字符串：");
                String tmp = scanner.nextLine();
                if("end".equals(tmp)){
                    break;
                }else {
                    char[] arr = tmp.toCharArray();
                    Arrays.sort(arr);

                    for(int i=arr.length-1;i>=0;i--){
                        fw.write(arr[i]);
                    }
                    fw.write("\n");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(fw!=null){
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
